Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Configuration
Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Graphics
Imports Microsoft.Xna.Framework.Input
Imports Microsoft.Xna.Framework.Media
Imports Microsoft.Xna.Framework.Input.Touch
Imports Microsoft.Xna.Framework.Content

Module Program
    Sub New()
    End Sub
    ''' <summary>
    ''' The main entry point for the application.
    ''' </summary>
    Sub Main(args As String())
        Using game As New Game()
            game.Run()
        End Using
    End Sub





    Public Function LoadContent(Of T)(contentManager As ContentManager, contentFolder As String) As Dictionary(Of [String], T)
        Dim result As New Dictionary(Of [String], T)()
        Dim key As String = String.Empty
#If ANDROID Then
		key = "Tiles/BlockA"
		result(key.ToUpper()) = contentManager.Load(Of T)(key)
		key = "Tiles/GateA"
		result(key.ToUpper()) = contentManager.Load(Of T)(key)
		key = "Tiles/SpaceA"
		result(key.ToUpper()) = contentManager.Load(Of T)(key)
		key = "Tiles/SpaceB"
		result(key.ToUpper()) = contentManager.Load(Of T)(key)
		Return result
#End If
#If WINDOWS Then
        'Load directory info, abort if none
        Dim dir As New DirectoryInfo(contentManager.RootDirectory & "/" & contentFolder)
        If Not dir.Exists Then
            Throw New DirectoryNotFoundException()
        End If




        Dim files = (From file In Directory.EnumerateFiles(contentManager.RootDirectory & "/" & contentFolder, "*.xnb", SearchOption.AllDirectories))




        For Each f As Object In files
            key = String.Empty
            Dim fileName As String = f.ToString().Replace("\"c, "/"c)
            Dim fileExtPos As Integer = fileName.LastIndexOf(".")
            If fileExtPos >= 0 Then
                fileName = fileName.Substring(0, fileExtPos)
            End If
            'remove contentManager.RootDirectory

            fileExtPos = fileName.LastIndexOf(contentManager.RootDirectory) + (contentManager.RootDirectory & "/").Length
            If fileExtPos >= 0 Then
                key = fileName.Substring(fileExtPos)
            End If



            Try
                'bug in the monogame load song, i will add the wav extension??!?!?
                If key.Contains("Songs/") = True Then
                    result(key.ToUpper()) = DirectCast(DirectCast(contentManager.Load(Of Song)(key & ".wav"), Object), T)
                Else
                    result(key.ToUpper()) = contentManager.Load(Of T)(key)
                End If
            Catch ex As Exception
                'result[f.N.ToUpper()] = contentManager.Load<T>(sFolder + key); 
            End Try
        Next

        Return result
#End If
    End Function
End Module

